<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
/*
 * This is company page.
 */
include 'config.php';
$comp = true;
?>
<html>
    <head>
        <title>Company</title>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <style media="all" type="text/css">@import "css/all.css";</style>
        <meta name="google-translate-customization" content="79f814d6e23ddcf4-dfbb1fb397ca28ad-g1e3566e08575f155-1b"></meta>
    </head>
    <body>
<script type="text/javascript">
//function googleTranslateElementInit() {
//  new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
//}
</script><script type="text/javascript" src="element.js?cb=googleTranslateElementInit"></script>

        <div id="main">
            <?php include 'nav.php'; ?>
            <div id="middle">
                <div id="left-column">
                    <h3>Company</h3>
                    <ul class="nav">
                        <li><a href="company">List</a></li>
                        <li class="last" ><a href="company?q=new">Add New</a></li>
                    </ul>
                    <h3>Pre-Paid Code</h3>
                    <ul class="nav" >
                        <li class="last"><a href="company?q=generate" >Generate New Code</a></li>
                        
                    </ul>
                </div>

                <!--             Details starts-->
                <div id="center-column">
                    <?php if ($_GET['q'] == '') { ?>
                        <div class="top-bar">
                            <h1>Company List,</h1>
                            <div class="breadcrumbs"><a href="index">Homepage</a></div>
                        </div>
                        <br /><hr/> 
                        <b>This screen will give you a quick overview of all companies selling pre-paid codes. </b><br/>

                        <div class="table"  >
                            <img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
                            <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
                            <table class="listing" cellpadding="0" cellspacing="0">
                                <tr>
                                    <th class="first">Company</th>
                                    <th>Seller</th>
                                    <th>Email</th>
                                    <th>Country</th>                                    
                                </tr>
                                <?php
                                $q2 = mysql_query("select * from salus_company_list ");
                                while ($row = mysql_fetch_array($q2)) {
                                    ?>                                                          
                                    <tr class="bg" >
                                        <td class="first style1"><a href="company?q=detail&id=<?=$row['id']?>" ><?= $row[1] ?></a></td>
                                        <td><?= $row[2] ?></td>
                                        <td><?= $row[3] ?></td>
                                        <td><?php
                            $country = mysql_fetch_array(mysql_query("select name from fa_country where id = $row[4] ")) or die(mysql_error());
                            echo $country[0];
                                    ?></td>
                                    </tr>
                                <?php } ?>
                            </table>                        
                        </div>
                    <?php } elseif ($_GET['q'] == 'new') { ?>
                        <div class="top-bar">
                            <h1>Create New Company,</h1>                        
                        </div>
                        <br>
                        <form action="Com/company_operations.php" method="post" >
                            <br><hr>
                            <table>
                                <tr>
                                    <td>Company Name :</td>
                                    <td><input type="text" name="company_name" required /></td>
                                </tr>
                                <tr>
                                    <td>Seller Name :</td>
                                    <td><input type="text" name="seller_name" required /></td>
                                </tr>
                                
                                <tr>
                                    <td>Company E-mail :</td>
                                    <td><input type="text" name="email" required /></td>
                                </tr>
                                <tr>
                                    <td>Country :</td>
                                    <td>
                                        <select name="nation" style="width: 175px;" required >
                                        <?php
                                            $n1 = mysql_query("select * from fa_country");
                                            while ($nation1 = mysql_fetch_array($n1)) {?>
                                            <option value="<?=$nation1['id']?>" ><?=$nation1['name']?></option>  
                                        <?php }?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td><input type="hidden" name="action" value="new" /></td>
                                    <td><input type="submit" style="height: 40px;" value="Add New Company" /></td>
                                </tr>
                            </table>
                        </form>
                    <?php }elseif($_GET['q']=='edit'){ ?>
                        <div class="top-bar">
                            <h1>Company Detail,</h1>                        
                        </div><br><br><hr>
                        <?php $cdetail = mysql_query("select * from salus_company_list where id='".$_GET['id']."'") or die(mysql_error()) ;?>
                            <form action="Com/company_operations.php" method="post" >
                        <?php while($cd = mysql_fetch_array($cdetail)){ ?>
                                
                            <table>
                                <tr>
                                    <td>Company Name :</td>
                                    <td><input type="text" name="company_name" value="<?=$cd['company_name']?>" required /></td>
                                </tr>
                                <tr>
                                    <td>Seller Name :</td>
                                    <td><input type="text" name="seller_name" value="<?=$cd['seller_name']?>" required /></td>
                                </tr>
                                
                                <tr>
                                    <td>Company E-mail :</td>
                                    <td><input type="text" name="email" value="<?=$cd['email']?>" required /></td>
                                </tr>
                                <tr>
                                    <td>Country :</td>
                                    <td>
                                        <select name="nation" style="width: 175px;" required >
                                        <?php
                                            $n1 = mysql_query("select * from fa_country");
                                            while ($nation1 = mysql_fetch_array($n1)) {?>
                                            <option <?php if($cd['nation']==$nation1['id']) echo 'selected'; ?>  value="<?=$nation1['id']?>" ><?=$nation1['name']?></option>  
                                        <?php }?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td><input type="hidden" name="action" value="update" />
                                        <input type="hidden" name="id" value="<?=$cd['id']?>" /></td>
                                    <td><input type="submit" style="height: 40px;" value="Update Company" /></td>
                                </tr>
                            </table>

                        <?php }?>
                            </form>
                            <?php } elseif($_GET['q']=='detail'){ ?>
                        <div class="top-bar">
                            <h1>Company Detail,</h1>                        
                        </div>
                        <br /><hr/>                   
                        <?php
                        $cdetail = mysql_query("select * from salus_company_list where id='".$_GET['id']."'") or die(mysql_error()) ;
                        while($cd = mysql_fetch_array($cdetail)){
                        ?>
                        
                            <table>
                                <tr>
                                    <td>Company Name :</td>
                                    <td><b><?=$cd['company_name']?></b></td>
                                </tr>
                                <tr>
                                    <td>Seller Name :</td>
                                    <td><b><?=$cd['seller_name']?></b></td>
                                </tr>
                                
                                <tr>
                                    <td>Company E-mail :</td>
                                    <td><b><?=$cd['email']?></b></td>
                                </tr>
                                <tr>
                                    <td>Country :</td>
                                    <td><b>
                                       
                                        <?php
                                            $n1 = mysql_query("select * from fa_country where id='".$cd['nation']."' ");
                                            while ($nation1 = mysql_fetch_array($n1)) {
                                                echo $nation1['name'];
                                            }?></b>                                       
                                    </td>                                    
                                </tr>    
                                <tr>
                                    <td></td>
                                    <td><a href="company?q=edit&id=<?=$cd['id']?>"><img src="img/edit-icon.gif" title="Edit Company Info" /></a></td>
                                </tr>
                            </table><br/><hr/>
                             <div class="top-bar">
                            <h1>Log :</h1>
                        </div><hr>
                            <div class="table">
				<img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
				<img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
				<table class="listing" cellpadding="0" cellspacing="0">
					<tr>
						<th class="first" width="20px">Sr.</th>
						<th>Product</th>
						<th>Total Pre-paid Codes</th>	
                                                <th>Subscription Type</th>
						<th class="last">Date</th>
					</tr>
                                        <?php $i=1; $gg= mysql_query("select * from salus_seller_details where cid='".$_GET['id']."' ") or die(mysql_error());
                                                 while ($row1 = mysql_fetch_array($gg)) { ?>
                                    <tr>
                                        <td><?=$i?></td>
                                        <td><?php
 
                                      $pro1 =  mysql_fetch_array(mysql_query("select product from products where id = '".$row1['product_id']."' ")) or die(mysql_error());
                                      echo $pro1['product'];
                                        ?>
                                                     </td>
                                        <td><?=$row1['total_codes']?></td>
                                        <td>
                                            <?php
                                              $sub1 = mysql_fetch_array(mysql_query("select product_year  from salus_buy_detail where id = '".$row1['pro_detail_id']."' ")) or die(mysql_error());
                                              echo $sub1['product_year'];
                                            ?>
                                        </td>
                                        <td><?=$row1['purchase_date']?></td>
                                    </tr>
                                        <?php $i++; } ?>
                                </table><br/><hr>
                                    <div class="top-bar">
                                        <h1>Company's code List</h1>
                                    </div><br/><hr>
                                         <div class="table">
				<img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
				<img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
				<table class="listing" cellpadding="0" cellspacing="0">
					<tr>
						<th class="first" width="20px">Sr.</th>
						<th>Product</th>
						<th>Pre-paid Codes</th>	
                                                <th>Subscription Type</th>
						<th class="last">Status</th>
					</tr>
                                                                  
                                        <?php $j = 1;
                                            $c0 = mysql_query("select * from salus_seller_details where cid ='".$_GET['id']."' ") or die(mysql_error());
                                            while ($row2 = mysql_fetch_array($c0)) {
                                                $sr = $row2['sr'];
                                                $c1 = mysql_query("select * from salus_prepaid_codes where seller_detail_id = $sr ") or die(mysql_error());
                                                while ($row3 = mysql_fetch_array($c1)) {?>
                                    <tr>
                                        <td><?=$j++?></td>
                                        <td>
                                            <?php
 
                                      $pro2 =  mysql_fetch_array(mysql_query("select product from products where id = '".$row2['product_id']."' ")) or die(mysql_error());
                                      echo $pro2['product'];
                                        ?>
                                        </td>
                                        <td><?=$row3['prepaid_code']?></td>
                                        <td>
                                            <?php
                                              $sub2 = mysql_fetch_array(mysql_query("select product_year  from salus_buy_detail where id = '".$row2['pro_detail_id']."' ")) or die(mysql_error());
                                              echo $sub2['product_year'];
                                            ?>
                                        </td>
                                        <td><?php
                                            if($row3['user_id']!=''){
                                                echo '<font color=red>Used</font>';
                                            }else{
                                                echo '<font color=green>Un-used</font>';
                                            }
                                        
                                        ?></td>
                                    </tr>
                                                <?php }
                                            }
                                        ?>
                                                                                
                                    
                                </table>
                                         </div>
                            </div>
                            
                        <?php  } } elseif($_GET['q']=='generate'){ ?>
                        <div class="top-bar">
                            <h1>Code Generate,</h1>                        
                        </div>
                        <br />                  
                        <?php $cdetail = mysql_query("select * from salus_company_list") or die(mysql_error()) ; ?>                        
                        <form action="Com/company_operations.php" method="post" >
                            <br><hr>
                            <table>
                                <tr>
                                    <td>Select Company :</td>
                                    <td><select name="company_id" >
                                            <?php while($cd = mysql_fetch_array($cdetail)){ ?>
                                            <option value="<?=$cd['id']?>" > <?=$cd['company_name']?>  </option>
                                            <?php } ?>
                                        </select>                                        
                                    </td>
                                </tr>
                                <tr>
                                    <td>Select Product :</td>
                                    <td><?php $pr1 = mysql_query("select * from products ")  ; ?>
                                        <select name="product_id" >
                                            <?php while ($pr2 = mysql_fetch_array($pr1)) {?>
                                            <option value="<?=$pr2['id']?>" ><?=$pr2['product']?></option>                                                    
                                            <?php } ?>
                                        </select>
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td>Insert total required number of pre-paid code :</td>
                                    <td>
                                        <input type="text" name="yr1" placeholder="total codes"   />*  &nbsp;  -> 1 year<br>
                                        <input type="text" name="yr3" placeholder="total codes"   />*  &nbsp;  -> 3 year<br>
                                        <input type="text" name="yr5" placeholder="total codes"   />*  &nbsp;  -> 5 year<br>
                                            <font color="red" > *Keep blank if not want to insert</font>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Total Cost :</td>
                                    <td><input type="text" name="cost" required /></td>
                                </tr>
                                <tr>
                                    <td>Discount :</td>
                                    <td><input type="text" name="discount" required /></td>
                                </tr>
                                <tr>
                                    <td><input type="hidden" name="action" value="generate" /></td>
                                    <td><input type="submit" style="height: 40px;" value="Generate Code" /></td>
                                </tr>
                            </table><br/><hr/>
                        </form>  
                            
                        <?php } ?>                             
                            
                </div>
                <div id="right-column">
                    <strong class="h">INFO</strong>
                    <div class="box">Welcome to Adminpanel.<br> Add company and generate pre-paid code. </div><br/><br/><br/><br/>
                   <div id="google_translate_element"></div>
                </div>
                
            </div>
            <div id="footer">Developed By SpearBall Inc. : Savan Koradia</div>
        </div>


    </body>   
</html>
